<template>
	<view class="release">
		<cu-custom bgColor="bg-gradual-purple" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">历史版本</block>
		</cu-custom>
		
		<Loading :loadModal="loadModal" :hint="hint"></Loading>
		<view class="cu-timeline" v-if="logs.length>0">
			<view class="cu-item" v-for="(item,index) in logs" :key="index">
				<view class="content">
					<view class="cu-capsule radius">
						<view class="cu-tag bg-cyan">v{{item.content.releaseName}}</view>
						<view class="cu-tag line-cyan">{{item.content.releaseDate}}</view>
					</view>
					<view :class="idx=='0'?'margin-top':''" v-for="(childItem,idx) in item.content.releaseContent" :key="idx">
						{{childItem}}
					</view>
				</view>
			</view>
		</view>
		<Nodata :noModal="nodata"></Nodata>
	</view>
</template>

<script>
	import Loading from '../../components/loading.vue';
	import Nodata from '../../components/nodata.vue';
	import util from '../../utils/util.js';
	import api from '../../utils/api.js';
	export default {
		components: {
			Loading,
			Nodata
		},
		data() {
			return {
				imgUrl: getApp().globalData.imgUrl,
				loadModal: false, //加载
				hint: '加载中...', //加载提示
				nodata: false,
				logs: [],
				page: 1,
			}
		},

		onLoad: async function(options) {
			await this.getReleaseLogs();
		},
		methods: {
			getReleaseLogs:async function(refresh = '') {
				this.hint = refresh == 'below' ? '刷新中...' : '加载中...';
				if (refresh == 'below' || this.page == 1) {
					this.logs = [];
				} //清空列表
				this.loadModal = true;
				let result = await api.getReleaseLogsList(this.page);
				this.loadModal = false;
				uni.stopPullDownRefresh();
				let list = result.data;
				this.logs = this.page == 1 ? list : [...this.logs, ...list];
				this.nodata = list.length === 0 && this.page == 1 ? true : false;
				if (list.length == 0) {
					uni.showToast({
						title: '没有更多了！',
						icon: 'none',
						duration: 2000
					})
				}
			}
		},
		onPullDownRefresh: async function ()  { //下拉刷新
			this.page = 1;
			await this.getReleaseLogs('below');
			// console.log('onPullDownRefresh');
		},
		onReachBottom: async function () { //上拉加载
			this.page = this.page + 1;
			await this.getReleaseLogs('up');
			// console.log('onReachBottom');
		},
	}
</script>

<style>
	
</style>
